/**
 *
 */
package org.ddevil.data.set;

import org.ddevil.data.Data;

/**
 * A DataSet where each record can be uniquely identified by key attributes.
 * Key attributes are set by their DB Identifiers.
 * <p>
 *
 * <strong>NOTE: If the DataSet has more then one record with the same key
 * then behavior is undefined.</strong>
 *
 *
 * @author Rich O'Connell
 *
 */
public interface KeyedDataSet<T extends Data> extends DataSet<T> {

    /**
     * Set the Keys that will uniquely define a record in this DataSet.
     *
     * @param dbids
     *      The IDs of the attributes that make up the key.
     */
    public void setKey(String ... dbids);

    /**
     * Export the record that is represented by the given key.
     *
     * @param keyData
     *          The key attributes that define the record we want.
     * @return
     *          The full record represented by the given key.
     */
    public T exportRecord(T keyData);

    /**
     * Remove the record with the given key.
     *
     * @param keyData
     *      The key for the record to remove.
     */
    public void removeRecord(T keyData);


    /**
     * Replace the record with the same key as the new record with
     * the new record.  If no record exists with those keys the new
     * record is just added.
     *
     * @param newRecord
     */
    public void replaceRecord(T newRecord);

    /**
     * Import the new record to this data set.  If a record allready exists
     * with the new records keys then the new record is merged in.  Only attributes
     * present in the new record will be updated in the current record.
     */
    public void importRecord(T inData);
    
    /**
     * Does this set already contain the record in question?
     * @param data
     * @return
     */
    boolean contains(T data);

}
